﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TaskSchedulingSystemForm.MailSend;
using TaskSchedulingSystemForm.Model;

namespace TaskSchedulingSystemForm.Common
{
    public static class Mail
    {
        public static void SendMail(Enum errType,string stackDetail,TaskModel ta = null)
        {
            string subject = "";
            subject += "[TXSS]";
            string ErrorInfo = "";
            ArrayOfString to = new ArrayOfString();
            to.Add("zhangzy@txsec.com");
            ArrayOfString cc = new ArrayOfString();
            ArrayOfString bcc = new ArrayOfString();
            subject += "任务调度系统系统异常邮件";
            string body = "";
            if (ta != null)
            {
                body = string.Format("错误类型：{0}<br>任务名称：{1}<br>堆栈详情：",EnumHelper.GetDescription(errType), ta.taskName);
            }
            MailSend.ServiceSoapClient s = new ServiceSoapClient();
            s.SendMailAuto(to, cc, bcc, subject, body+stackDetail, "", "", true, ref ErrorInfo);
            if (ErrorInfo == "")
            {
                TSSLog.WrriteXTLog( "\n" + "系统错误邮件发送成功!");
            }
            else
            {
                TSSLog.WrriteXTLog("\n" + "系统错误邮件发送失败!");
            }          
        }
    }
}
